package com.bw.zhuangao5___day002.Fragment;


import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.bw.mvp.V.BannerFragment;
import com.bw.zhuangao5___day002.Fragment.Music.JavaMuisc;
import com.bw.zhuangao5___day002.Fragment.Music.MuiscBaseAdpter;
import com.bw.zhuangao5___day002.Fragment.Music.MuiscContion;
import com.bw.zhuangao5___day002.Fragment.Music.MuiscModel;
import com.bw.zhuangao5___day002.Fragment.Music.MuiscPretenter;
import com.bw.zhuangao5___day002.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentMusic extends BannerFragment implements MuiscContion.misview, OnRefreshLoadMoreListener {

    MuiscBaseAdpter baseAdpter;
    MuiscPretenter muiscPretenter;
    private SmartRefreshLayout MuiscSmart;
    private RecyclerView MuiscReview;
    public  boolean ispps=true;
    public  int number = 1;

    @Override
    public int bandLayoud() {
        return R.layout.fragment_blank_fragment_music;
    }

    @Override
    public void initView() {

        MuiscSmart = (SmartRefreshLayout) findViewById(R.id.Muisc_smart);
        MuiscReview = (RecyclerView) findViewById(R.id.Muisc_review);
        MuiscSmart.setOnRefreshLoadMoreListener(this);
        MuiscReview.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        muiscPretenter = new MuiscPretenter(this,new MuiscModel());
        muiscPretenter.doginit("/zytestapi/video/findVideos?currentPage="+number+"&pageSize=10");
    }

    @Override
    public void initDate() {

    }

    @Override
    public void getmisview(List<JavaMuisc.DataBean> dataBeans) {
        MuiscSmart.finishLoadMore();
        MuiscSmart.finishRefresh();
        if (baseAdpter ==null)
        {
            baseAdpter = new MuiscBaseAdpter(dataBeans);
            MuiscReview.setAdapter(baseAdpter);
        }else {
            if (ispps)
            {
                baseAdpter.getData().clear();
            }
            baseAdpter.getData().addAll(dataBeans);
            baseAdpter.notifyDataSetChanged();
        }

    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

        ispps=false;
        number++;
        muiscPretenter.doginit("/zytestapi/video/findVideos?currentPage="+number+"&pageSize=10");
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (ispps)
        {
            number=5;
        }
        muiscPretenter.doginit("/zytestapi/video/findVideos?currentPage="+number+"&pageSize=10");
    }
}
